<?php

ob_start();

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <title>Home</title>
    </head>
    <body>
        <?php
        
        
        if (strlen(session_id()) == 0)
            session_start();

        if (isset($_SESSION['popupshowed'])) {
            $popupshowed = $_SESSION['popupshowed'];
        } else {
            $popupshowed = 0;
        }
        $_SESSION['popupshowed'] = '1';

        //session expiration
        if (isset($_SESSION['expiretime'])) {
            if ($_SESSION['expiretime'] < time()) {
                $_SESSION['popupshowed'] = '0';
            } else {
                $_SESSION['expiretime'] = time() + 1800;
            }
        }

        $_SESSION['expiretime'] = time() + 1800;

        include('inc/init.php');
        $smarty->assign('title', $title);
        $smarty->template_dir = 'templates';
        $smarty->assign('title', $title);
        $smarty->assign('popupshowed', $popupshowed);

        $feats = $db->prepare("select
            t1.*, t3.city,
            (select count(t2.id) from ats_itinerary t2 where t2.packageid=t1.id) as days
            from ats_package t1
            inner join ats_city t3 on t1.cityid=t3.id
            where t1.featured = 1 limit 0,3");

        $feats->execute();
        $feats->setFetchMode(PDO::FETCH_ASSOC);
        $frontimages = $db->prepare("select t1.*, t2.dest_id
            from ats_frontimages t1
            left outer join ats_package t2
            on t1.packageid=t2.id
            where active=1");

        $frontimages->execute();
        $frontimages->setFetchMode(PDO::FETCH_ASSOC);
        $smarty->assign('feats', $feats);
        $smarty->assign('frontimages', $frontimages);
        $smarty->display('index.tpl');
        
        ob_end_flush();
        ?>

    </body>

</html>